package cn.myplus.blog.response;

import cn.myplus.blog.BaseDto;
import cn.myplus.blog.catalog.dto.CatalogDto;
import org.springframework.http.ResponseEntity;
import org.springframework.web.util.UriComponentsBuilder;

import java.util.List;

/**
 * @author libo.
 * @date 2022/5/29
 */
public class ResponseEntityUtil {

    public static ResponseEntity created(BaseDto dto) {
        UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(dto.getLink());
        org.springframework.http.ResponseEntity.BodyBuilder created = org.springframework.http.ResponseEntity.created(uriComponentsBuilder.build(true).toUri());
        return created.body(dto);
    }

    public static ResponseEntity ok(BaseDto dto) {
        return ResponseEntity.ok(dto);
    }

    public static ResponseEntity list(List<BaseDto> dtos) {
        return ResponseEntity.ok(dtos);
    }

    public static ResponseEntity listWithPage(List<CatalogDto> dtos) {
        ResponseBodyWithMeta responseBody = new ResponseBodyWithMeta();
        responseBody.setPagination(new Pagination());
        responseBody.setData(dtos);
        return ResponseEntity.ok(responseBody);
    }
}
